package com.study.controller.user;

import com.study.dto.CouponDTO;
import com.study.entity.Coupon;
import com.study.result.Result;
import com.study.service.CouponService;
import com.study.vo.CouponVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/user/coupon")
@Api(tags = "优惠券相关接口")
public class CouponController {

    @Autowired
    CouponService couponService;

    /**
     * 根据用户id获取优惠券
     *
     * @param couponDTO
     * @return
     */
    @PostMapping("/list")
    @ApiOperation(value = "根据用户id和优惠券状态获取优惠券")
    public Result<List<CouponVO>> getCouponByUserId(@RequestBody CouponDTO couponDTO) {
        List<CouponVO> couponList = couponService.getList(couponDTO);
        return Result.success(couponList);
    }

    /**
     * 用户领取优惠券(根据优惠券id)
     * @param couponId
     * @return
     */
    @PostMapping("/getCoupon/{couponId}")
    @ApiOperation(value = "领取优惠券(根据优惠券id)")
    public Result<String> userGetCoupon(@PathVariable Long couponId) {
        couponService.userGetCoupon(couponId);
        return Result.success();
    }

    /**
     * 查询所有可用优惠券
     */
    @GetMapping("/getAllCoupon")
    @ApiOperation(value = "查询所有可用优惠券")
    public Result<List<Coupon>> getAllCoupon() {
        List<Coupon> couponList = couponService.getAllCoupon();
        return Result.success(couponList);
    }

    /**
     * 条件查询优惠券
     * @param couponDTO
     * @return
     */
    @PostMapping("/getCouponByCondition")
    @ApiOperation(value = "条件查询优惠券")
    public Result<List<Coupon>> getCouponByCondition(@RequestBody CouponDTO couponDTO) {
        List<Coupon> couponList = couponService.getListByCondition(couponDTO);
        return Result.success(couponList);
    }

    /**
     * 返回用户已领取的优惠券id集合
     * @param userId
     * @return
     */
    @GetMapping("/getUserCouponIdList/{userId}")
    @ApiOperation(value = "返回用户已领取的优惠券id集合")
    public Result<List<Long>> getUserCouponIdList(@PathVariable Long userId) {
        List<Long> couponIdList = couponService.getUserCouponIdList(userId);
        return Result.success(couponIdList);
    }
}

